package com.ruoyi.business.service.impl;

import java.time.*;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.BusinessClockMapper;
import com.ruoyi.business.domain.BusinessClock;
import com.ruoyi.business.service.IBusinessClockService;

/**
 * 考勤Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-04
 */
@Service
public class BusinessClockServiceImpl implements IBusinessClockService 
{
    @Autowired
    private BusinessClockMapper businessClockMapper;

    /**
     * 查询考勤
     * 
     * @param clockId 考勤主键
     * @return 考勤
     */
    @Override
    public BusinessClock selectBusinessClockByClockId(Long clockId)
    {
        return businessClockMapper.selectBusinessClockByClockId(clockId);
    }

    /**
     * 查询考勤列表
     * 
     * @param businessClock 考勤
     * @return 考勤
     */
    @Override
    public List<BusinessClock> selectBusinessClockList(BusinessClock businessClock)
    {
        return businessClockMapper.selectBusinessClockList(businessClock);
    }

    /**
     * 新增考勤
     * 
     * @param businessClock 考勤
     * @return 结果
     */
    @Override
    public int insertBusinessClock(BusinessClock businessClock)
    {
        long clockStatus=businessClock.getClockStatus();
        if(businessClock.getClockTime()==null){
            Date fixedTime=new Date();
            if(clockStatus==1){
                // 获取当前日期
                LocalDate today = LocalDate.now();

                // 创建一个指定时间的 LocalTime 对象
                LocalTime fixedTime1 = LocalTime.of(8, 0, 0);

                // 将当前日期与指定时间结合
                LocalDateTime localDateTime = LocalDateTime.of(today, fixedTime1);
                ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault()); // 将 LocalDateTime 转换为 ZonedDateTime
                fixedTime = Date.from(zonedDateTime.toInstant()); // 将 ZonedDateTime 转换为 Date 对象


            }
            if (clockStatus==2){
                // 获取当前日期
                LocalDate today = LocalDate.now();

                // 创建一个指定时间的 LocalTime 对象
                LocalTime fixedTime1 = LocalTime.of(17, 0, 0);

                // 将当前日期与指定时间结合
                LocalDateTime localDateTime = LocalDateTime.of(today, fixedTime1);
                ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault()); // 将 LocalDateTime 转换为 ZonedDateTime
                fixedTime = Date.from(zonedDateTime.toInstant()); // 将 ZonedDateTime 转换为 Date 对象

            }
            if (clockStatus==3){
                // 获取当前日期
                LocalDate today = LocalDate.now();

                // 创建一个指定时间的 LocalTime 对象
                LocalTime fixedTime1 = LocalTime.of(8, 0, 1);

                // 将当前日期与指定时间结合
                LocalDateTime localDateTime = LocalDateTime.of(today, fixedTime1);
                ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault()); // 将 LocalDateTime 转换为 ZonedDateTime
                fixedTime = Date.from(zonedDateTime.toInstant()); // 将 ZonedDateTime 转换为 Date 对象

            }
            if (clockStatus==4){
                // 获取当前日期
                LocalDate today = LocalDate.now();

                // 创建一个指定时间的 LocalTime 对象
                LocalTime fixedTime1 = LocalTime.of(16, 59, 59);

                // 将当前日期与指定时间结合
                LocalDateTime localDateTime = LocalDateTime.of(today, fixedTime1);
                ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault()); // 将 LocalDateTime 转换为 ZonedDateTime
                fixedTime = Date.from(zonedDateTime.toInstant()); // 将 ZonedDateTime 转换为 Date 对象

            }
            businessClock.setClockTime(fixedTime);
        }
        return businessClockMapper.insertBusinessClock(businessClock);
    }

    /**
     * 修改考勤
     * 
     * @param businessClock 考勤
     * @return 结果
     */
    @Override
    public int updateBusinessClock(BusinessClock businessClock)
    {
        return businessClockMapper.updateBusinessClock(businessClock);
    }

    /**
     * 批量删除考勤
     * 
     * @param clockIds 需要删除的考勤主键
     * @return 结果
     */
    @Override
    public int deleteBusinessClockByClockIds(Long[] clockIds)
    {
        return businessClockMapper.deleteBusinessClockByClockIds(clockIds);
    }

    /**
     * 删除考勤信息
     * 
     * @param clockId 考勤主键
     * @return 结果
     */
    @Override
    public int deleteBusinessClockByClockId(Long clockId)
    {
        return businessClockMapper.deleteBusinessClockByClockId(clockId);
    }
}
